#coding:utf8

file = open("D:\data.txt")
rs_file = open("D:\out.txt", "w+")
onlineDay = 1
pre_driver = ""

for line in file.readlines():
    driver = line.split("\t")[0]
    week_count = line.split("\t")[2]#周几
    week_day = line.split("\t")[1]#第几周
    is_online = line.split("\t")[3]
    print(line)
    if pre_driver != driver:
        if "" != pre_driver and onlineDay != 0 :
            print(driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")
            rs_file.writelines(pre_driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")

        pre_driver = driver
        onlineDay = 0

    if onlineDay == 7:
        # print("driver:" + driver + ",在第" + str(week_count) + "周的第" + str(week_day) + "天，连续上线" + str(onlineDay) + "天")
        print(driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")
        rs_file.writelines(driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")
        onlineDay = 0

    if int(is_online) == 1:
        onlineDay += 1
    else:
        if onlineDay != 0:
            print(driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")
            rs_file.writelines(driver + "," + str(week_count) + "," + str(week_day) + "," + str(onlineDay) + "\n")
            onlineDay = 0

    rs_file.flush()

rs_file.close()
file.close()
